package cc.booku.owlbox.InitPage;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import androidx.appcompat.app.AppCompatActivity;

import cc.booku.owlbox.R;


/**
 * 配文字环形进度条
 */
public class TextRoundActivity extends AppCompatActivity {
    private static final int MSG_REFRESH_PROGRESS = 1001;
    private static final int TIME_REFRESH = 8000;
    private TextRoundProgress trp135; // 起始角度设置为135
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MSG_REFRESH_PROGRESS:
                    trp135.setProgress(msg.arg1);
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_round);
        initView();
        timer.startLoopTimer(TIME_REFRESH);
    }

    private void initView() {
        trp135 = (TextRoundProgress) findViewById(R.id.trp_135);
    }

    private void refresh() {
        //final int percent = RandomUtil.getRandomPercent();
        new Thread(new Runnable() {
            Message msg = null;

            @Override
            public void run() {
                int start = 0;
                while (start <= 100) {
                    msg = new Message();
                    msg.what = MSG_REFRESH_PROGRESS;
                    msg.arg1 = start;
                    handler.sendMessage(msg);
                    start++;
                    try {
                        Thread.sleep(25);
                    } catch (InterruptedException e) {
                    }
                }
            }
        }).start();
    }

    private MyTimer timer = new MyTimer(this) {
        @Override
        public void timerCallBack() {
            refresh();
        }
    };
}
